<?php

/*
Zoo Management Simulation
This is the Admin UI. It provides an overview of the cages.
*/

include("dbconnect.php");
$sql = 'SELECT * FROM enclosure';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoo Management Administator Page</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="wrapper">
<h1>Zoo Management Administator Page</h1>
<div id="buttoninterface">
<?php
  echo "<form id='adminCageForm' name='adminCageForm' method='post' enctype='multipart/form-data' action='adminCageProcess.php'>";
  echo "<input type='submit' name='submit' id='submit' value='Lock all doors' />";
  echo "</form>";
?>
</div>
<div id="content">
<?php
$cagenumber = 1;
foreach ($dbh->query($sql) as $row)
	{
		$entryopensql = "SELECT entryId FROM entry WHERE enclosureId=".$row[0]." and isEntryOpen=1";
		$door = 0;
		foreach ($dbh->query($entryopensql) as $entryrow)
		{
			$door += 1;
		}
		if ($row[7]==1){
			$light="On";
		}
		elseif ($row[7]==0){
			$light="Off";
		}
		
		if ($row[8]==1){
			$locked="Locked";
		}
		elseif ($row[8]==0){
			$locked="Unlocked";
		}
		
		echo "<form id='CageForm' name='CageForm' method='post' enctype='multipart/form-data' action='adminCageProcess.php?id=".$row[0]."'>";
		echo "<div class='zoobox'>";
		echo "<div class='zoopicture'>";
		echo "<a href='cage.php?cageid=".$row[0]."&cagenumber=". $cagenumber."' title='".$row[1]."'><img src='zoo/cp2013 from James/".$door."doorLights".$light.$locked.".png' width='201' height='165' /></a>";
		echo "</div>";
		echo "<div class='zooinfo'>";
		if ($row[8]==1){
			echo "<input type='submit' name='submit' id='submit' value='Unlock' />";
		}
		elseif ($row[8]==0){
			echo "<input type='submit' name='submit' id='submit' value='Lock' />";
		}
		echo "<input type='submit' name='submit' id='submit' value='Toggle Lighting' />";
		echo "</div>";
		echo "</div>";
		echo "</form>";
		$cagenumber+=1;
	}
$dbh = null;
?>
</div>

<div id="buttoninterface">
<p>
<?php
  echo "<form id='adminCageForm' name='adminCageForm' method='post' enctype='multipart/form-data' action='adminCageProcess.php'>";
  echo "<input align='middle' type='submit' name='submit' id='submit' value='Show Setup' />";
  echo "</form>";
?>
</p>
</div>
</body>
</html>